package com.iris.temp;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Random;
import java.util.Set;


/**
 * @date : 2017年3月30日 下午1:51:08
 * @author : Iris.Xiao
 * @version : 1.0
 * @description : 
*/
public class Test6 {
	static {
		i=0;//给变量赋值可以正常编译通过
//		System.out.print(i);//这句编译器会提示"非法向前引用"

	}
	public static int i=1;
	

	public static enum CmdConfig{
		ACCOUNT1("/root/drive/lizhao"),
		ACCOUNT2("/root/drive/lizhao"),
		ACCOUNT3("/root/drive/lizhao"),
		ACCOUNT4("/root/drive/lizhao"); 
		private String config;
		CmdConfig(String config){
			this.config = config;
		}
		public String getConfig() {
			return config;
		}
		
		public CmdConfig getCmdConfig(String name){
			return CmdConfig.valueOf(name);
		}
	}
	
	public static void main(String[] args) {
		Test6 test = new Test6();
//		System.out.println(test.random(1.151D, 2.2D));
//		long sss = (long) 343.34D;
//		System.out.println(sss);
		test.test11();
	}
	
	public void test11(){
		Integer a = 1;
		Integer b = 2;
		Integer c = 3;
		Integer d = 3;
		Integer e = 321;
		Integer f = 321;
		  
		Long g = 3L;
		Long h = 2L;
		  
		// 会自动拆箱（会调用intValue方法）
		System.out.println(c==d);
		// 会自动拆箱后再自动装箱
		System.out.println(e==f);
		// 虽然“==”比较的是引用的是否是同一对象，但这里有算术运算，如果该引用为包装器类型则会导致自动拆箱
		System.out.println(c==(a+b));
		// equals 比较的是引用的对象的内容（值）是否相等，但这里有算术运算，如果该引用为包装器类型则会导
		 // 致自动拆箱，再自动装箱
		// a+b触发自动拆箱得到值后，再自动装箱与c比较
		System.out.println(c.equals(a+b));
		// 首先a+b触发自动拆箱后值为int型，所以比较的是值是否相等
		System.out.println(g==(a+b));
		// 首先a+b触发自动拆箱后值为int型，自动装箱后为Integer型，然后g为Long型
		System.out.println(g.equals(a+b));
		// 首先a+h触发自动拆箱后值为long型，因为int型的a会自动转型为long型的g然后自动装箱后为Long型，
		 // 而g也为Long型
		System.out.println(g.equals(a+h));
	}

	public void test10(){
		String synDate = "2017-08-08";
		String compareDate = "2017-08-07 00:11:11";
		System.out.println(synDate.compareTo(compareDate));
	}
	
	public void test9(){
		System.out.println(0.3-0.2);
	}
	
	public void test8(){
	String str = "12";
	SimpleDateFormat sdf = new SimpleDateFormat("MM");
	Date date = null;
	try {
		date = sdf.parse(str);
	} catch (ParseException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	sdf = new SimpleDateFormat("MMMMM",Locale.US);
	System.out.println(sdf.format(date));
	
	Timestamp ts = Timestamp.valueOf("2017-07-10");
	System.out.println(ts.getTime());
	}
	
	public void test7(){
		String[] fileIds = {"1","2","3","4","5","6","7","8","9","10"};
		int lengthSplit=3;
		if(fileIds!=null&&fileIds.length>lengthSplit){
			List<String> fileIdsList = new ArrayList<String>();
			String[] fileIdsNew = null; 
			for (int j = 1; j <= fileIds.length; j++) {
				if(j>0&&j%lengthSplit==0){
					fileIdsList.add(fileIds[j-1]);
					fileIdsNew = fileIdsList.toArray(new String[]{});
					for (String string : fileIdsNew) {
						System.out.println(string);
					}
					fileIdsList.clear();
				}else if(j== fileIds.length){
					fileIdsList.add(fileIds[j-1]);
					fileIdsNew = fileIdsList.toArray(new String[]{});
					for (String string : fileIdsNew) {
						System.out.println(string);
					}
					fileIdsList.clear();
				}else{
					fileIdsList.add(fileIds[j-1]);
				}
			}
		}
	}
	
	
	public void test6(){
		Calendar calendar  = Calendar.getInstance();
		//昨天的数据
		calendar.add(Calendar.MONTH, -5);
		System.out.println(calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
		System.out.println(calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
	}
	
	
	public void test5(){
		String tt = "sssssss\tdddddddddd\taaaaaaa";
		System.out.println(tt);
		System.out.println(tt.getBytes().toString());
		String[] tta= tt.split("\t");
		for (int i = 0; i < tta.length; i++) {
			System.out.println(tta[i]);
		}
		byte[]  b = " ".getBytes();
		for (byte c : b) {
			System.out.println(c);
		}
		b = "\t".getBytes();
		for (byte c : b) {
			System.out.println(c);
		}
		b = "\n".getBytes();
		for (byte c : b) {
			System.out.println(c);
		}
		
		
	}

	public void test4(){
		String iconUrl = "https://3dzed-xjp.s3-ap-southeast-1.amazonaws.com/video/5ee6220b41c54327a3065ac7aaa2c8e5.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20170619T064031Z&X-Amz-SignedHeaders=host&X-Amz-Expires=518400&X-Amz-Credential=AKIAJZVQPIT5GDN3EKFQ%2F20170619%2Fap-southeast-1%2Fs3%2Faws4_request&X-Amz-Signature=18556e20835bcaeeb2c742604fa5e77534cdb0ecfab7066ece8235541ac6004e";
		if(iconUrl.contains("?")){
			iconUrl = iconUrl.substring(0, iconUrl.indexOf("?"));
		}
		System.out.println(iconUrl);
	}
	
	public void test3(){
		Set<String> siteIdsTemp = new HashSet<String >();
		siteIdsTemp.add("ddddd");
		siteIdsTemp.add("aaaaaa");
		System.out.println(siteIdsTemp.toString());
	}
	

    public Double random(Double min,Double max){
    	int i = 100;
    	Double d = 100D;
    	int minInt = (int) (min*i);
    	int maxInt = (int) (max*i);
    	int minus = maxInt-minInt;
    	Random random = new Random();
    	int rand = random.nextInt(minus);
    	Double resultInt = (rand+minInt)/d;
    	return resultInt;
    }
    
    public void test2(){
    	System.out.println(new BigDecimal(0.001D).setScale(0, RoundingMode.UP).doubleValue());
//		Calendar calendar  = Calendar.getInstance();
//		calendar.add(Calendar.DATE, -80);
//		System.out.println(new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime()));
    }
	
	public void test1(){

		String str = "PT10M7S";
		String st1 = String.format("%02d", 1);     
		System.out.println(st1);
		
		//PT10M7S>10:07
		String durationStr = "PT1H";
		
		durationStr = durationStr.replaceAll("PT", "");//.replaceAll("H", ":").replaceAll("M", ":").replaceAll("S", "");
		System.out.println(durationStr);
		String hour = "0";
		if(durationStr.contains("H")){
			hour = durationStr.substring(0, durationStr.indexOf("H"));
			durationStr = durationStr.substring(durationStr.indexOf("H")+1, durationStr.length());
			System.out.println("hour=="+hour);
		}
		String minite = "0";
		if(durationStr.contains("M")){
			minite = durationStr.substring(0, durationStr.indexOf("M"));
			durationStr = durationStr.substring(durationStr.indexOf("M")+1, durationStr.length());
			System.out.println("minite=="+minite);
		}
		String second = "0";
		if(durationStr.contains("S")){
			second = durationStr.substring(0, durationStr.indexOf("S"));
			durationStr = durationStr.substring(durationStr.indexOf("S")+1, durationStr.length());
			System.out.println("second=="+second);
		}
		String timeStr="";
		if("0".equals(hour)){
			timeStr = String.format("%02d:%02d", Integer.parseInt(minite),Integer.parseInt(second));
		}else{
			timeStr = String.format("%02d:%02d:%02d",Integer.parseInt(hour), Integer.parseInt(minite),Integer.parseInt(second));
		}
		System.out.println(timeStr);
//		
//		for (int i = 0; i < 6; i++) {
//			System.out.println(i+"===out");
//			for (int j = 0; j < 5; j++) {
//				System.out.println(i+"===in=="+j);
//				if(i==2){
//					break;
//				}
//			}
//		}

//		Integer i1 = new Integer(19);
//		Integer i2 = new Integer(33333);
//		System.out.println(i1==19);
//		System.out.println(i2==33333);
//		System.out.println("ssssss\\xF0ddfff\\x9Fddsf\\x8E\\x9E\\xEF".toString().replaceAll("[\\ud800\\udc00-\\udbff\\udfff\\ud800-\\udfff]", ""));
//		System.out.println("ssssss\\xF0ddfff\\x9Fzzzz\\x8E\\x9E\\xEF".toString().replaceAll("\\\\x[0-9a-zA-Z][0-9a-zA-Z]", ""));
//		System.out.println("\\xF0\\x9F\\x8E\\x9E\\xEF");
//		MessageFormat mf = new MessageFormat("");
//		System.out.println(mf.format(""));
		
//		String dollarReplace = "$0.00";
//		System.out.println(dollarReplace.replaceAll("\\$", ""));
//		String datatime = "2017-05-19T07:00:00+0000";
//		System.out.println(datatime.substring(0, 10));
		System.out.println(Math.round(12321.7423D));
		
		int[] test=new  int[10000];
		for (int i = 0; i < 10000; i++) {
			test[i]=i;
		}
		long start = System.currentTimeMillis();
//		for (int i : test) {
//			System.out.println(i);
//		}
		long end = System.currentTimeMillis();
		long m1 = end-start;

		int index=0;

//		start = System.currentTimeMillis();
//		for (int i : test) {
//			System.out.println(test[index++]);
//		}
//		end = System.currentTimeMillis();
		long m2 = end-start;
		index=45;
		System.out.println(m1+"==========="+m2);
		System.out.print(test[(index++)]);
//		System.out.print(test[index++]);
	}

}
